home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABText.c
-
- NAME
- ABText.c, part of the ABox project source code,
- responsible for handling the AboutBox Text class stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 9 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 28-july-94 - ty - 1.0.6--additions to support settable drag mgr usage
- via the ABox Get/SetProperty methods
- 26-apr-95 - ty - 1.0.7--small fixes to tighten up scrolling vs drag handling
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABText.h"
- #include "ABox.h"
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABText::ABText ================================*/
- ABText::ABText(void)
- {
- //visibleObject = true;
- mTEh = NULL;
- mScrollH = NULL;
- mResType = kABtextResource;
- } // end ABText
-
-
-
-
- /*=============================== ABText::~ABText ================================*/
- ABText::~ABText(void)
- {
- if (this->HasTEh())
- {
- ::TEDispose (this->TEh());
- this->TEh() = NULL;
- }
-
- if (this->HasScrollbar())
- {
- ::DisposeControl(this->Scrollbar());
- this->Scrollbar() = NULL;
- }
-
- } // end ~ABText
-
-
-
-
-
- /*=============================== ABText::Draw ================================*/
- OSErr ABText::Draw(WindowPtr window)
- {
- OSErr error = noErr;
- // begin here...
-
- error = ABObject::Draw(window);
-
- if (error == noErr)
- error = this->InitializeResource();
-
- //if (this->HasScrollbar())
- this->ObjectRect().right -= kABscrollBarWidth;
-
- if (error == noErr)
- {
- Rect box;
- long teHeight;
- long firstLine = 0;
-
- box = this->ObjectRect();
-
- if (this->DoesntHaveTEh())
- {
- error = this->BuildText(&box, this->OurWindowRef());
- if (this->DoesntHaveTEh())
- {
- // TENew failed, so let's just do a simple NeoTextBox here...
- //
- // now move the right side back out because
- // we won't use a scroll bar
- box.right -= kABscrollBarWidth;
- ::HLockHi (this->ResourceHandleRef());
- error = this->DrawTextBox (
- (unsigned char *)&(this->ResourceHandleRef())[1], // unsigned char *c
- **(this->ResourceHandleRef()), // unsigned long textSize
- &box, // Rect *displayWrapRect
- teJustCenter, // short alignmentConstants
- 0, // lineHeightCode (0 = default)
- NULL, // short *endY baseline
- NULL); // short *lineHeight
- ::HUnlock (this->ResourceHandleRef());
-
- this->ObjectRect().right += kABscrollBarWidth;
- return error;
- } // end if else block
-
- } else {
-
- ::TEUpdate (&box, this->TEh());
- } // end if else block
-
- // the scroll bar _might_ be needed, so determine just
- // how tall the text is on the screen, and how tall could
- // it be (potential height, if all text were being displayed)
- //
- ::HLockHi (this->ResourceHandleRef());
- teHeight = ::TEGetHeight ((*(this->TEh()))->nLines, firstLine, this->TEh());
- ::HUnlock (this->ResourceHandleRef());
-
- if (teHeight >= (box.bottom - box.top))
- {
- if (this->DoesntHaveScrollbar())
- {
- // need the scroll bar...
- Rect scrollbarRect;
-
- scrollbarRect.top = box.top - 1;
- scrollbarRect.bottom = box.bottom + 1;
- scrollbarRect.left = box.right + 1;
- scrollbarRect.right = scrollbarRect.left + kABscrollBarWidth;
-
- this->Scrollbar() = ::NewControl (this->GetWindow(), // the window
- &scrollbarRect, // the rect
- "\pVScroll", // the title
- true, // visible
- 1, // initial value
- 1, // minimum value
- teHeight, // maximum value
- scrollBarProc, // control is a scrollbar
- (long)(this->TEh())); // the reference constant
-
- error = ::ResError();
-
- } // end if (scrollH) block
-
- if (this->HasScrollbar())
- {
- // make it visible
- ::ShowControl (this->Scrollbar());
- ::HiliteControl (this->Scrollbar(), kActivateControl);
-
- this->FixScrollBar (this->Scrollbar());
- } // end if else block...
-
- } // end if else block...
-
- }
-
- this->ObjectRect().right += kABscrollBarWidth;
-
- return error;
-
- } // end Draw
-
-
-
-
- /*=============================== ABText::BuildText ================================*/
- OSErr ABText::BuildText(Rect* area, WindowPtr /*window*/)
- {
- OSErr error = noErr;
-
- StScrpHandle styleHandle = NULL;
-
- Rect box;
-
- long textLen = 0;
-
- // begin here...
-
- if (area)
- box = *area;
- else
- box = this->ObjectRect();
-
- // see if we can find out a little more on the text resource...if it has
- // a corresponding 'styl' resource.
-
- // we have the information, so now try to load a style 'styl' resource
- // and use it for the text.
- styleHandle = (StScrpHandle)::Get1Resource (kABStyleResource, this->ResID());
- error = ::ResError();
- if (error)
- {
- // something's amiss...
- this->TEh() = ::TENew (&box, &box);
- styleHandle = NULL;
- error = noErr;
- } else {
- // nope, no problems, we have a TEXT and a styl resource,
- // so create a stylized text record
- this->TEh() = ::TEStylNew (&box, &box);
- } // end if block...
-
- if (this->DoesntHaveTEh())
- {
- error = paramErr;
- } else {
-
- // insert the text into the TEHandle
- //
- textLen = ::GetHandleSize (this->ResourceHandleRef());
- ::HLockHi (this->ResourceHandleRef());
- if (styleHandle)
- {
- TEActivate (this->TEh());
- TEStylInsert(*(this->ResourceHandleRef()), textLen, styleHandle, this->TEh());
- TEDeactivate (this->TEh());
-
- } else {
- TEInsert(*(this->ResourceHandleRef()), textLen, this->TEh());
- } // end if (styleHandle) block
- ::HUnlock(this->ResourceHandleRef());
-
- // release the style resource that shadows the text
- if (styleHandle)
- {
- ::ReleaseResource((Handle)styleHandle);
- } // end if block
-
- }
-
- return error;
- } // end BuildText
-
-
-
-
-
- /*=============================== ABText::Update ================================*/
- OSErr ABText::Update(WindowPtr window)
- {
-
- OSErr error = noErr;
-
- // begin here...
- //
- // Draw a bezel around the field _including_ the scroll bar
- //
- //error = ABObject::Update(window);
- this->OurWindowRef() = window;
- error = this->DrawFrame();
- if (this->HasTEh() && (error == noErr))
- {
- Rect box = this->ObjectRect();
- ::TEUpdate (&box, this->TEh());
- } // end if block
-
- return error;
-
- } // end Update
-
-
-
-
-
- /*=============================== ABText::Event ================================*/
- Boolean ABText::Event(EventRecord *event)
- {
- Boolean handled = false;
- Point where;
- OSErr error = noErr;
- Rect scrollBarRect;
- Rect box = this->ObjectRect();
-
- // begin here...
- //
- if (!event || this->DoesntHaveWindow())
- return false;
-
- switch (event->what)
- {
- case mouseDown:
- // 1.0.6 ty--check to see if we're allowed to use the DragMgr
- //
- ABox *theABox = (ABox *)::GetWRefCon (this->OurWindowRef());
- Boolean useDrag = false;
-
- if (theABox)
- error = theABox->GetProperty(kABoxUseDragMgr, &useDrag, NULL);
-
- where = event->where;
- ::GlobalToLocal(&where);
- if (::FrontWindow() != this->OurWindowRef())
- break;
-
- if (this->HasScrollbar())
- {
- scrollBarRect = (*(this->Scrollbar()))->contrlRect;
- if (::PtInRect(where, &scrollBarRect))
- {
- this->ScrollBarClick( this->Scrollbar(), where );
- this->FixScrollBar (this->Scrollbar());
- handled = true;
- } // end if block
- }
-
- if (::PtInRect (where, &box) && ABUEnvDragMgr::IsPresent() && useDrag && !handled) {
- // DragMgr stuff here!!!
-
- if (::WaitMouseMoved(event->where))
- {
- // the user is trying to Drag
- // from the field to someplace
- this->DragMgrEventRef() = event;
- error = this->Begin();
- error = this->End();
- } // end if block
- } // end if block
- break;
- default:
- break;
- } // end switch block
-
- return handled;
- } // end Event
-
-
-
-
- /*=============================== ABText::Stop ================================*/
- OSErr ABText::Stop(void)
- {
- OSErr error = noErr;
-
- // begin here...
- //
- if (this->HasScrollbar())
- {
- ::DisposeControl (this->Scrollbar());
- this->Scrollbar() = NULL;
- } // end if block
-
- error = kABTextSuperProperties::Stop();
- return error;
-
- } // end Stop
-
-
-
-
-
- /*=============================== ABText::Initialize ================================*/
- OSErr ABText::Initialize(void)
- {
- OSErr error = noErr;
- Ptr ptr = NULL;
- Size ptrSize = 0;
- StScrpHandle theStyle;
-
- // OVERRIDE of the ABUEnvDragMgr method!
- if (this->IsDragInitialized())
- return noErr;
-
- this->DragRectRef() = this->ObjectRect();
- error = ABUEnvDragMgr::Initialize();
- if (error)
- return error;
-
- error = ::SetDragSendProc (this->DragRef(),
- this->DragUPPRef(),
- this);
- if (error)
- return error;
-
- // now create the Send information
- ::HLock (this->ResourceHandleRef());
- ptr = (Ptr)*(this->ResourceHandleRef());
- ptrSize = ::GetHandleSize(this->ResourceHandleRef());
- error = ::AddDragItemFlavor(this->DragRef(),
- this->ItemRef(),
- kABtextResource,
- ptr,
- ptrSize,
- kABdefaultFlavorFlags);
- ::HUnlock (this->ResourceHandleRef());
-
- // now add the 2nd flavor, the style stuff
- theStyle = ::GetStylScrap(this->TEh());
- ::HLock((Handle) theStyle);
- ptr = (Ptr)*theStyle;
- ptrSize = ::GetHandleSize((Handle)theStyle);
- error = ::AddDragItemFlavor(this->DragRef(),
- this->ItemRef(),
- kABstyleResource,
- ptr,
- ptrSize,
- kABdefaultFlavorFlags);
- ::HUnlock((Handle) theStyle);
- ::DisposeHandle((Handle) theStyle);
-
-
- this->DragInitializedRef() = true;
-
- return error;
-
- } // end Initialize
-
-
-
-
-
- /*=============================== ABText::Begin ================================*/
- OSErr ABText::Begin(void)
- {
- OSErr error;
-
- // OVERRIDE of the ABUEnvDragMgr method! but be certain to call
- // the ABUEnvDragMgr method when finished here!!!!
-
- error = this->Initialize();
- if (error)
- return error;
-
- error = ABUEnvDragMgr::Begin();
-
- return error;
-
- } // end Begin
-
-
-
-
-
- /*=============================== ABText::LocalSendProc ================================*/
- //
- OSErr ABText::LocalSendProc(FlavorType theType,
- void* /*dragSendRefCon*/,
- ItemReference theItemRef,
- DragReference theDragRef)
- {
- OSErr error = noErr;
- Ptr ptr = NULL;
- Size ptrSize = 0;
- StScrpHandle theStyle;
-
- // begin here...
-
- if (theType == kABstyleResource)
- {
-
- theStyle = ::GetStylScrap(this->TEh());
-
- //
- // Call SetDragItemFlavorData to provide the requested data.
- //
-
- ::HLock((Handle) theStyle);
- ptr = (Ptr)*theStyle;
- ptrSize = ::GetHandleSize((Handle)theStyle);
- error = ::SetDragItemFlavorData(theDragRef,
- theItemRef,
- kABstyleResource,
- ptr,
- ptrSize,
- kABdefaultFlavorFlags);
- ::HUnlock((Handle) theStyle);
- ::DisposeHandle((Handle) theStyle);
-
- } else {
-
- return badDragFlavorErr;
-
- }
-
- return error;
-
- } // end LocalSendProc()
-
-
-
-
-
- // end of file
-
-